package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.uuid.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ArNoPolicyMapper;
import com.ruoyi.system.domain.ArNoPolicy;
import com.ruoyi.system.service.IArNoPolicyService;

/**
 * 档号规则信息Service业务层处理
 * 
 * @author ruoyi_ln
 * @date 2022-03-01
 */
@Service
public class ArNoPolicyServiceImpl implements IArNoPolicyService 
{
    @Autowired
    private ArNoPolicyMapper arNoPolicyMapper;

    /**
     * 查询档号规则信息
     * 
     * @param recNo 档号规则信息ID
     * @return 档号规则信息
     */
    @Override
    public ArNoPolicy selectArNoPolicyById(String recNo)
    {
        return arNoPolicyMapper.selectArNoPolicyById(recNo);
    }

    /**
     * 查询档号规则信息列表
     * 
     * @param arNoPolicy 档号规则信息
     * @return 档号规则信息
     */
    @Override
    public List<ArNoPolicy> selectArNoPolicyList(ArNoPolicy arNoPolicy)
    {
        return arNoPolicyMapper.selectArNoPolicyList(arNoPolicy);
    }

    /**
     * 新增档号规则信息
     * 
     * @param arNoPolicy 档号规则信息
     * @return 结果
     */
    @Override
    public AjaxResult insertArNoPolicy(ArNoPolicy arNoPolicy)
    {
        arNoPolicy.setRecNo(UUID.randomUUIDPlus());
        arNoPolicy.setCreateTime(DateUtils.getNowDate());
        arNoPolicy.setCreateBy(SecurityUtils.getUsername());
        arNoPolicy.setDelFlag("0");
        // 验证档号规则
        if (!StringUtils.checkFileFsmt(arNoPolicy.getFileFsmt())){
            // 如果结尾是 “-”，就把它删除掉
            arNoPolicy.getFileFsmt().substring(0,arNoPolicy.getFileFsmt().length() - 1);
        }
        arNoPolicyMapper.insertArNoPolicy(arNoPolicy);
        return AjaxResult.success();
    }

    /**
     * 修改档号规则信息
     * 
     * @param arNoPolicy 档号规则信息
     * @return 结果
     */
    @Override
    public AjaxResult updateArNoPolicy(ArNoPolicy arNoPolicy)
    {
        arNoPolicy.setUpdateTime(DateUtils.getNowDate());
        arNoPolicy.setUpdateBy(SecurityUtils.getUsername());
        // 验证档号规则
        if (!StringUtils.checkFileFsmt(arNoPolicy.getFileFsmt())){
            // 如果结尾是 “-”，就把它删除掉
            arNoPolicy.getFileFsmt().substring(0,arNoPolicy.getFileFsmt().length() - 1);
        }
        arNoPolicyMapper.updateArNoPolicy(arNoPolicy);
        return AjaxResult.success();
    }

    /**
     * 批量删除档号规则信息
     * 
     * @param recNos 需要删除的档号规则信息ID
     * @return 结果
     */
    @Override
    public AjaxResult deleteArNoPolicyByIds(String[] recNos)
    {
        arNoPolicyMapper.deleteArNoPolicyByIds(recNos);
        return AjaxResult.success();
    }

    /**
     * 删除档号规则信息信息
     * 
     * @param recNo 档号规则信息ID
     * @return 结果
     */
    @Override
    public AjaxResult deleteArNoPolicyById(String recNo)
    {
        arNoPolicyMapper.deleteArNoPolicyById(recNo);
        return AjaxResult.success();
    }
}
